/**
 * 微信回调页面地址的IP+port，以及调用接口的ip+port
 */
let interface_ip_port = "http://111.17.201.197:999"
let page_ip_port = "http://111.17.201.197:55000"
let redirect_uri_token = `${page_ip_port}/wechat/getToken`
//在微信端获取token的回调地址
let weixin_callback_url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8066c3c5aade3186&redirect_uri=${redirect_uri_token}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`


/*
    将通用的几个方法一起放在这
*/
// 获取url中的名为key的参数
let getParams = function (key) {
    //http://localhost:8080/#/getToken?code=081q2o000TA6zN1f1n300FN5cd4q2o0h&state=STATE
    let href = window.location.href;
    //对url进行解码
    console.log("解码前window.location.href=====>", href);
    href = decodeURIComponent(href);
    console.log("解码后window.location.href=====>", href);
    let reg = new RegExp(`[?]?${key}=(.*)($|(?=&))`);
    let r = reg.exec(href);
    if (!isEmpty(r) && r.length >= 2) {
        return r[1];
    }
    return null;
}
// 创建a标签并模拟点击事件
let clickA = function (url) {
    console.log("url=============" + url);
    if (isEmpty(url)) {
        alert("参数错误");
        return;
    }
    let a = document.createElement("a");
    a.style.display = "none";
    a.href = url;
    a.target = "_blank";
    document.body.appendChild(a);
    // 点击
    a.click();
    // 下载完成移除元素
    document.body.removeChild(a);
}
// 判空,是否为空，是空就返回真
let isEmpty = function (data) {
    if (
        data != null &&
        data !== "" &&
        data !== undefined &&
        data !== "undefined"
    ) {
        return false;
    }
    return true;
}


export { interface_ip_port, page_ip_port, weixin_callback_url,getParams,clickA,isEmpty }